﻿using AdminStystem.Domain;
using AdminSytem.Application.Dto;
using AdminSytem.Repositories;
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminSytem.Application.Processingrs
{
    public class ProcessingrServices : IProcessingrServices
    {
        private readonly IRepository<Processingr> processingrRepository;
        private readonly IRepository<PEnterprise> pEnterpriseRepository;
        private readonly IRepository<RawMaterial> rawMaterialRepository;
        private readonly IRepository<Accessories> accessoriesRepository;
        private readonly IRepository<Additive> additiveRepository;
        private readonly IRepository<PackagingMaterials> packagingMaterialsRepository;
        private readonly IMapper mapper;

        public ProcessingrServices(IRepository<Processingr> processingrRepository, IMapper mapper, IRepository<PEnterprise> pEnterpriseRepository, IRepository<RawMaterial> rawMaterialRepository, IRepository<Accessories> accessoriesRepository, IRepository<Additive> additiveRepository, IRepository<PackagingMaterials> packagingMaterialsRepository)
        {
            this.processingrRepository = processingrRepository;
            this.mapper = mapper;
            this.pEnterpriseRepository = pEnterpriseRepository;
            this.rawMaterialRepository = rawMaterialRepository;
            this.accessoriesRepository = accessoriesRepository;
            this.additiveRepository = additiveRepository;
            this.packagingMaterialsRepository = packagingMaterialsRepository;
        }
        /// <summary>
        /// 添加深加工信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ResultDto<int>> AddProcessingr(ProcessingrDto dto)
        {
            ResultDto<int> result = new ResultDto<int>();
            result.StatusCode = StatusCode.Success;
            result.Message = "添加成功";
            var processingr = mapper.Map<Processingr>(dto);
            var entity = await processingrRepository.InsertAsync(processingr);
            return result;
        }
        /// <summary>
        /// 获取深加工信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<ResultDto<Processingr>> GetProcessingr(int id)
        {
            ResultDto<Processingr> result = new ResultDto<Processingr>();
            result.StatusCode = StatusCode.Success;
            result.Message = "查询成功";
            var list = await processingrRepository.QueryFirstAsync(a => a.GoodsId == id);
            result.Data = list;
            return result;
        }
        /// <summary>
        /// 添加加工企业信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ResultDto<int>> AddPEnterprise(PEnterpriseDto dto)
        {
            ResultDto<int> result = new ResultDto<int>();
            result.StatusCode = StatusCode.Success;
            result.Message = "添加成功";
            var processingr = mapper.Map<PEnterprise>(dto);
            var entity = await pEnterpriseRepository.InsertAsync(processingr);
            return result;
        }
        /// <summary>
        /// 获取加工企业信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<ResultDto<PEnterprise>> GetPEnterprise(int id)
        {
            ResultDto<PEnterprise> result = new ResultDto<PEnterprise>();
            result.StatusCode = StatusCode.Success;
            result.Message = "查询成功";
            var list = await pEnterpriseRepository.QueryFirstAsync(a => a.GoodsId == id);
            result.Data = list;
            return result;
        }
        public async Task<ResultDto<int>> AddrawMaterial(RawMaterialDto dto)
        {
            ResultDto<int> result = new ResultDto<int>();
            result.StatusCode = StatusCode.Success;
            result.Message = "添加成功";
            var entity=mapper.Map<RawMaterial>(dto);
           await rawMaterialRepository.InsertAsync(entity);
            return result;
        }
        public async Task<ResultDto<RawMaterial>> GetRawMaterial(int id)
        {
            ResultDto<RawMaterial> result = new ResultDto<RawMaterial>();
            result.StatusCode = StatusCode.Success;
            result.Message = "查询成功";
            var list = await rawMaterialRepository.QueryFirstAsync(a => a.GoodsId == id);
            result.Data = list;
            return result;
        }
        public async Task<ResultDto<int>> AddAccessories(AccessoriesDto dto)
        {
            ResultDto<int> result = new ResultDto<int>();
            result.StatusCode = StatusCode.Success;
            result.Message = "添加成功";
            var entity = mapper.Map<Accessories>(dto);
            await accessoriesRepository.InsertAsync(entity);
            return result;
        }
        public async Task<ResultDto<Accessories>> GetAccessories(int id)
        {
            ResultDto<Accessories> result = new ResultDto<Accessories>();
            result.StatusCode = StatusCode.Success;
            result.Message = "查询成功";
            var list = await accessoriesRepository.QueryFirstAsync(a => a.GoodsId == id);
            result.Data = list;
            return result;
        }
        public async Task<ResultDto<int>> AddAdditive(AdditiveDto dto)
        {
            ResultDto<int> result = new ResultDto<int>();
            result.StatusCode = StatusCode.Success;
            result.Message = "添加成功";
            var processingr = mapper.Map<Additive>(dto);
            var entity = await additiveRepository.InsertAsync(processingr);
            return result;
        }
        public async Task<ResultDto<Additive>> GetAdditive(int id)
        {
            ResultDto<Additive> result = new ResultDto<Additive>();
            result.StatusCode = StatusCode.Success;
            result.Message = "查询成功";
            var list = await additiveRepository.QueryFirstAsync(a => a.GoodsId == id);
            result.Data = list;
            return result;
        }
        public async Task<ResultDto<int>> AddPackagingMaterials(PackagingMaterialsDto dto)
        {
            ResultDto<int> result = new ResultDto<int>();
            result.StatusCode = StatusCode.Success;
            result.Message = "添加成功";
            var processingr = mapper.Map<PackagingMaterials>(dto);
            var entity = await packagingMaterialsRepository.InsertAsync(processingr);
            return result;
        }
        public async Task<ResultDto<PackagingMaterials>> GetPackagingMaterials(int id)
        {
            ResultDto<PackagingMaterials> result = new ResultDto<PackagingMaterials>();
            result.StatusCode = StatusCode.Success;
            result.Message = "查询成功";
            var list = await packagingMaterialsRepository.QueryFirstAsync(a => a.GoodsId == id);
            result.Data = list;
            return result;
        } 
    }
}
